//
//  YZSanitarianVC.m
//  VET
//
//  Created by 刘文靖 on 2018/7/21.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZSanitarianVC.h"
#import "YZLineView.h"
#import "YZPlaceholderTextView.h"
#import "YZClickOptionBtn.h"
#import "YZArchieveOptionVC.h"
#import "YZDatePickView.h"
#import "YZAutoCache.h"
#import "YZSwineryModel.h"
#import "YZWorkNoteModel.h"
#import "YZSwineOptionPickerView.h"
#import "YZAutoItemModel.h"
#import "YZRouter+AutoVC.h"
#import "YZAutoRowModel.h"
#import "NSDate+YZDatePickView.h"
#import "ZYKeyboardUtil.h"
@interface YZMedicineView : UIView
@property (strong, nonatomic) UILabel *descLabel;
@property (strong, nonatomic) YZClickOptionBtn *medicineNameBtn;///<药物名称
@property (strong, nonatomic) UITextField *dosageTF;///<使用剂量
@property (strong, nonatomic) YZClickOptionBtn *dosageUnitBtn;///<剂量单位
@property (strong, nonatomic) YZClickOptionBtn *methodBtn;///<使用方法
@property (strong, nonatomic) UITextField *daysTF;///<使用天数
@property (strong, nonatomic) YZAutoRowModel *selectedMedicine;///<选择的药物
@property (strong, nonatomic) YZAutoItemModel *selectedDosageUnit;///<选择的剂量单位
@property (strong, nonatomic) YZAutoItemModel *selectedMethod;///<选择的使用方法
@property (strong, nonatomic) UIButton *deleteBtn;
@property (strong, nonatomic) ZYKeyboardUtil *keyboardUtil;
@end

@implementation YZMedicineView
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    
    self = [super initWithCoder:aDecoder];
    if (self) {
        
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    self.backgroundColor = kColorWithHex(0xffffff);
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = kColorWithHex(0xE9EAEB);
    [self addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.mas_equalTo(46);
    }];
    self.descLabel = [[UILabel alloc] init];
    self.descLabel.textColor = kColorWithHex(0x434343);
    self.descLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [topView addSubview:self.descLabel];
    [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(18);
    }];
    
    self.deleteBtn = [[UIButton alloc] init];
    [self.deleteBtn setImage:[UIImage imageNamed:@"ico_delete"] forState:UIControlStateNormal];
    [self.deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteBtn setTitleColor:kColorWithHex(0x46596F) forState:UIControlStateNormal];
    self.deleteBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [topView addSubview:self.deleteBtn];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-25);
        make.bottom.offset(-9);
    }];
    
    self.medicineNameBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"药物名称"];
    [self addSubview:self.medicineNameBtn];
    [self.medicineNameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(self.descLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(54);
    }];
    
    UILabel *dosageLabel = [[UILabel alloc] init];
    dosageLabel.text = @"使用剂量";
    dosageLabel.textColor = kColorWithHex(0x393939);
    dosageLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [self addSubview:dosageLabel];
    [dosageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(17);
        make.top.mas_equalTo(self.medicineNameBtn.mas_bottom).offset(16);
    }];
    
    UILabel *dosageStarLabel = [[UILabel alloc] init];
    dosageStarLabel.text = @"*";
    dosageStarLabel.textColor = kColorWithHex(0xFF5656);;
    dosageStarLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];;
    [self addSubview:dosageStarLabel];
    [dosageStarLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(dosageLabel);
        make.size.mas_equalTo(CGSizeMake(6.5, 6.5));
        make.left.mas_equalTo(dosageLabel.mas_right).offset(9);
    }];
    
    
    self.dosageTF = [[UITextField alloc] init];
    self.dosageTF.textAlignment = NSTextAlignmentRight;
    self.dosageTF.placeholder = @"请填写";
    self.dosageTF.keyboardType = UIKeyboardTypeDecimalPad;
    [self addSubview:self.dosageTF];
    [self.dosageTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.medicineNameBtn.mas_bottom);
        make.height.mas_equalTo(54);
        make.right.offset(-18);
        make.width.mas_equalTo(100);
    }];
    
    YZLineView *dosageLine = [[YZLineView alloc] init];
    [self addSubview:dosageLine];
    [dosageLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(.5);
        make.left.offset(12);
        make.centerX.offset(0);
        make.bottom.mas_equalTo(self.dosageTF);
    }];
    
    self.dosageUnitBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"剂量单位"];
    [self addSubview:self.dosageUnitBtn];
    [self.dosageUnitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(dosageLine.mas_bottom);
        make.height.mas_equalTo(54);
    }];
    
    self.methodBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"使用方法"];
    [self addSubview:self.methodBtn];
    [self.methodBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(self.dosageUnitBtn.mas_bottom);
        make.height.mas_equalTo(54);
    }];
    
    UILabel *daysLabel = [[UILabel alloc] init];
    daysLabel.text = @"使用天数";
    daysLabel.textColor = kColorWithHex(0x393939);
    daysLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [self addSubview:daysLabel];
    [daysLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(17);
        make.top.mas_equalTo(self.methodBtn.mas_bottom).offset(16);
    }];
    
    UILabel *daysStarLabel = [[UILabel alloc] init];
    daysStarLabel.text = @"*";
    daysStarLabel.textColor = kColorWithHex(0xFF5656);;
    daysStarLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];;
    [self addSubview:daysStarLabel];
    [daysStarLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(daysLabel);
        make.size.mas_equalTo(CGSizeMake(6.5, 6.5));
        make.left.mas_equalTo(daysLabel.mas_right).offset(9);
    }];
    
    self.daysTF = [[UITextField alloc] init];
    self.daysTF.textAlignment = NSTextAlignmentRight;
    self.daysTF.placeholder = @"请填写";
    self.daysTF.keyboardType = UIKeyboardTypeDecimalPad;
    [self addSubview:self.daysTF];
    [self.daysTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.methodBtn.mas_bottom);
        make.height.mas_equalTo(54);
        make.right.offset(-18);
        make.width.mas_equalTo(100);
    }];
    [self configKeyBoardRespond];
    [self registClickEvents];
}

- (void)configKeyBoardRespond {
    self.keyboardUtil = [[ZYKeyboardUtil alloc] initWithKeyboardTopMargin:MARGIN_KEYBOARD];
    @weakify(self)
    [_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
        @strongify(self)
        [keyboardUtil adaptiveViewHandleWithAdaptiveView:self.dosageTF, self.daysTF,nil];
    }];
}

- (void)registClickEvents{
    @weakify(self)
     [[self.medicineNameBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
         @strongify(self)
         [self endEditing:YES];
         [[YZRouter sharedInstance] yz_atuoPush:@"care_medicine" params:nil itemClick:^(YZAutoRowModel *item) {
             self.selectedMedicine = item;
             self.medicineNameBtn.optionStr = item.displayValue;
         }] ;
    }];
    
    [[self.dosageUnitBtn  rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        [self endEditing:YES];
        [[[YZAutoCache sharedInstance] getAutoCellItems:@"dosag_unit"] subscribeNext:^(NSArray *items) {
           // self.items = items;
            [YZSwineOptionPickerView showStringPickerWithTitle:@"剂量单位"
                                                    dataSource:items
                                               defaultSelValue: nil
                                                  isAutoSelect:NO
                                                    themeColor:nil
                                                   resultBlock:^(YZAutoItemModel *item) {
                                        
                                                       self.selectedDosageUnit = item;
                                                       self.dosageUnitBtn.optionStr = item.itemValue;
                                                   }];
        }];
    }];
    
    [[self.methodBtn  rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        [self endEditing:YES];
        [[[YZAutoCache sharedInstance] getAutoCellItems:@"medicine_usage"] subscribeNext:^(NSArray *items) {
            //self.items = items;
            [YZSwineOptionPickerView showStringPickerWithTitle:@"使用方法"
                                                    dataSource:items
                                               defaultSelValue: nil
                                                  isAutoSelect:NO
                                                    themeColor:nil
                                                   resultBlock:^(YZAutoItemModel *item) {
                                                       self.selectedMethod = item;
                                                       self.methodBtn.optionStr = item.itemValue;
                                                   }];
        }];
    }];
}
@end



@interface YZSanitarianVC ()<UIScrollViewDelegate>
@property (strong, nonatomic) UIScrollView *mainScrollView;
@property (strong, nonatomic) YZClickOptionBtn *objcBtn;
@property (strong, nonatomic) YZClickOptionBtn *timeBtn;
@property (strong, nonatomic) YZClickOptionBtn *typeBtn;
@property (strong, nonatomic) UITextField *executorTF;
@property (strong, nonatomic) NSArray *objectIds;
@property (strong, nonatomic) NSArray *items;
@property (strong, nonatomic) YZAutoItemModel *selectedTypeItem;
@property (strong, nonatomic) UIView *medicineView;
@property (strong, nonatomic) UIButton *addMedicineBtn;
@property (strong, nonatomic) YZPlaceholderTextView *markTF;
@property (assign, nonatomic) NSInteger medicineNum;
@property (strong, nonatomic) NSDictionary *params;
@property (strong, nonatomic) ZYKeyboardUtil *keyboardUtil;
@end
#define medicineViewH  316
@implementation YZSanitarianVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationBar];
    [self setupMainView];
    [self configKeyBoardRespond];
}
- (void)setupNavigationBar{
    self.title = @"新增保健";
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 36, 25)];
    [rightButton setTitle:@"保存" forState:UIControlStateNormal];
    [rightButton setTitleColor:kColorWithHex(0x32BE60) forState:UIControlStateNormal];
    [rightButton setTitleColor:kColorWithHex(0xcecece) forState:UIControlStateDisabled];
    rightButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18];
    [rightButton addTarget:self action:@selector(saveSanitarian) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *righBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem = righBarButtonItem;
}

- (void)setupMainView{
    self.mainScrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    self.mainScrollView.backgroundColor  = kColorWithHex(0xE9EAEB);
    self.mainScrollView.delegate = self;
    self.mainScrollView.alwaysBounceVertical = YES;
    self.mainScrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.mainScrollView];
    
    UILabel *topDescLabel = [[UILabel alloc] init];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"*为必填项，请仔细填写" attributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Regular" size:12],NSForegroundColorAttributeName:kColorWithHex(0x7A7A7A)}];
    [attributedString addAttribute:NSForegroundColorAttributeName value:kColorWithHex(0xFF5656) range:(NSMakeRange(0, 1))];
    topDescLabel.attributedText = attributedString;
    [self.mainScrollView addSubview:topDescLabel];
    [topDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.top.offset(16);
    }];
    
    UIView *topView = [[UIView alloc] init];
    topView.backgroundColor = kColorWithHex(0xffffff);
    [self.mainScrollView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.width.mas_equalTo(kScreenWidth);
        make.top.mas_equalTo(topDescLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(216);
    }];
    
    self.objcBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"保健对象"];
    [topView addSubview:self.objcBtn];
    [self.objcBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.mas_equalTo(54);
    }];
    self.timeBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"保健时间"];
    [topView addSubview:self.timeBtn];
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.objcBtn.mas_bottom);
        make.left.right.offset(0);
        make.height.mas_equalTo(54);
    }];
    self.typeBtn = [[YZClickOptionBtn alloc] initWithDescStr:@"保健类型"];
    [topView addSubview:self.typeBtn];
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.timeBtn.mas_bottom);
        make.left.right.offset(0);
        make.height.mas_equalTo(54);
    }];
    
    UILabel *executorLabel = [[UILabel alloc] init];
    executorLabel.text = @"执行人";
    executorLabel.textColor = kColorWithHex(0x393939);;
    executorLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];;
    [topView addSubview:executorLabel];
    [executorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.typeBtn.mas_bottom).offset(16);
        make.left.offset(17);
    }];
    
    self.executorTF = [[UITextField alloc] init];
    self.executorTF.textAlignment = NSTextAlignmentRight;
    self.executorTF.placeholder = @"请填写";
    [topView addSubview:self.executorTF];
    [self.executorTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.typeBtn.mas_bottom);
        make.bottom.offset(0);
        make.right.offset(-18);
        make.width.mas_equalTo(100);
    }];
    
    self.medicineView = [[UIView alloc] init];
    [self.mainScrollView addSubview:self.medicineView];
    [self.medicineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(topView.mas_bottom);
    }];
    
    [self addMedicineWithIndex:self.medicineNum];
    
    self.addMedicineBtn = [[UIButton alloc] init];
    self.addMedicineBtn.backgroundColor = kColorWithHex(0xffffff);
    [self.addMedicineBtn setTitle:@"+新增药物" forState:UIControlStateNormal];
    [self.addMedicineBtn setTitleColor:kColorWithHex(0x32BE60) forState:UIControlStateNormal];
    self.addMedicineBtn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    [self.mainScrollView addSubview:self.addMedicineBtn];
    [self.addMedicineBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.height.mas_equalTo(52);
        make.top.mas_equalTo(self.medicineView.mas_bottom).offset(6);
    }];
    
    UILabel *markLabel = [[UILabel alloc] init];
    markLabel.textColor = kColorWithHex(0x434343);
    markLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
    markLabel.text = @"备注";
    [self.mainScrollView addSubview:markLabel];
    [markLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(18);
       make.top.mas_equalTo(self.addMedicineBtn.mas_bottom).offset(18);
    }];
    self.markTF = [[YZPlaceholderTextView alloc] init];
    self.markTF.placeholder = @"点击输入备注信息...";
    [self.mainScrollView addSubview:self.markTF];
    [self.markTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.mas_equalTo(markLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(120);
        make.bottom.offset(-60);
    }];
    @weakify(self)
    [[self.objcBtn  rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        [self.view endEditing:YES];
        YZArchieveOptionType optionType = [self.objectType isEqualToString:@"swine"]?YZArchieveOptionPig:YZArchieveOptionSwinery;
        YZArchieveOptionVC *optionVC = [[YZArchieveOptionVC alloc] initWithOptionType:optionType];
        optionVC.selectedModels = [NSMutableArray arrayWithArray:self.objectIds];
        optionVC.archieveSuccessBlock = ^(NSArray *selectedArr) {
            self.objectIds = selectedArr;
            self.objcBtn.optionStr = [NSString stringWithFormat:@"%lu个对象",(unsigned long)selectedArr.count];
        };
        [self.navigationController pushViewController:optionVC animated:YES];
    }];
    
    [[self.timeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.view endEditing:YES];
        [YZDatePickView showDatePickerWithTitle:@"保健时间"
                                       dateType:YZDatePickerModeDateAndTime
                                defaultSelValue:nil
                                        minDate:[NSDate date]
                                        maxDate:nil
                                   isAutoSelect:NO
                                     themeColor:nil
                                    resultBlock:^(NSString *selectValue) {
                                        self.timeBtn.optionStr = selectValue;
                                    }];
    }];
    
    [[self.typeBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.view endEditing:YES];
        [[[YZAutoCache sharedInstance] getAutoCellItems:@"care_type"] subscribeNext:^(NSArray *items) {
            self.items = items;
            [YZSwineOptionPickerView showStringPickerWithTitle:@"保健类型"
                                                    dataSource:self.items
                                               defaultSelValue: nil
                                                  isAutoSelect:NO
                                                    themeColor:nil
                                                   resultBlock:^(YZAutoItemModel *item) {
                                                       self.selectedTypeItem = item;
                                                       self.typeBtn.optionStr = item.itemValue;
                                                   }];
        }];
    }];
    
    [[self.addMedicineBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self.view endEditing:YES];
        ++self.medicineNum;
        [self addMedicineWithIndex:self.medicineNum];
    }];
}

- (void)addMedicineWithIndex:(NSInteger)index{
    [self.medicineView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(index * medicineViewH + medicineViewH);
    }];
    YZMedicineView *view = [[YZMedicineView alloc] init];
    [self.medicineView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(index * medicineViewH);
        make.height.mas_equalTo(medicineViewH);
        make.left.right.bottom.offset(0);
    }];
    view.descLabel.text = [NSString stringWithFormat:@"药物%ld",(long)index+1];
    view.deleteBtn.hidden = !index;
    @weakify(self)
    [[view.deleteBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self)
        --self.medicineNum;
        [view removeFromSuperview];
        [self.medicineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(self.medicineNum * medicineViewH + medicineViewH);
        }];
    }];
    
}

- (void)saveSanitarian{
    self.params = [self convertParams];
    if (self.params) {
        [[YZSwineryModelAPI addCare:self.params] subscribeError:^(NSError * _Nullable error) {
            NSLog(@"%@",error);
        } completed:^{
            [self.navigationController popViewControllerAnimated:YES];
        }];
    }else{
        [SVProgressHUD yz_showMessage:@"请将必填项输入完整"];
    }
}

- (NSDictionary *)convertParams{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"careExecutor"] = self.executorTF.text;
    params[@"remark"] = self.markTF.text;
    params[@"objectType"] = self.objectType;
    if (self.objectIds.count) {
        NSMutableArray *ids = [NSMutableArray array];
        for (YZArchiveModel *archive in self.objectIds) {
            [ids addObject:@(archive.archiveId)];
        }
        params[@"objectIds"] = ids;
    }else{
        return nil;
    }
    if (self.timeBtn.optionStr) {
        params[@"careTime"] = @([NSDate yz_getDateTimeInterval:self.timeBtn.optionStr format:@"yyyy-MM-dd HH:mm"]);
    }else{
        return nil;
    }
    if (self.selectedTypeItem) {
        params[@"careType"] = @(self.selectedTypeItem.itemKey);
    }else{
        return nil;
    }
    NSMutableArray *medicines = [NSMutableArray array];
    for (YZMedicineView *view in self.medicineView.subviews) {
        NSMutableDictionary *medicineDict = [NSMutableDictionary dictionary];
        if (view.selectedMedicine) {
            medicineDict[@"medicine"] = view.selectedMedicine.paramValue;
        }else{
            return nil;
        }
        if (view.dosageTF.text) {
            medicineDict[@"medicineDosage"] = view.dosageTF.text;
        }else{
            return nil;
        }
        if (view.selectedDosageUnit) {
            medicineDict[@"dosagUnit"] = @(view.selectedDosageUnit.itemKey);
        }else{
            return nil;
        }
        if (view.selectedMethod) {
            medicineDict[@"medicineUsage"] = @(view.selectedMethod.itemKey);
        }else{
            return nil;
        }
        if (view.daysTF.text) {
            medicineDict[@"medicineDuration"] = view.daysTF.text;
        }else{
            return nil;
        }
        [medicines addObject:medicineDict];
    }
     params[@"medicines"] = medicines;
    return params;
}

- (void)configKeyBoardRespond {
    self.keyboardUtil = [[ZYKeyboardUtil alloc] initWithKeyboardTopMargin:MARGIN_KEYBOARD];
    @weakify(self)
    [_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
        @strongify(self)
        [keyboardUtil adaptiveViewHandleWithController:self adaptiveView:self.markTF, nil];
    }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.view endEditing:YES];
}
@end
